package cn.easybuy.web.pre;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.service.impl.UserServiceImpl;

public class RegistServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String loginName=request.getParameter("loginName");
		String userName=request.getParameter("userName");
		String password=request.getParameter("password");
		String sex=request.getParameter("sex");
		String identityCode=request.getParameter("identityCode");
		String email=request.getParameter("email");
		String mobile=request.getParameter("mobile");
		User user=new User();
		user.setLoginName(loginName);
		user.setUserName(userName);
		user.setPassword(password);
		user.setSex(Integer.parseInt(sex));
		user.setIdentityCode(identityCode);
		user.setEmail(email);
		user.setMobile(mobile);
		UserService us=new UserServiceImpl();
		int num=us.saveUser(user);
		if (num>0) { //注册成功
			request.setAttribute("loginName", loginName);
			request.getRequestDispatcher("Login.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("Regist.html").forward(request, response);
		}
	}

}
